package com.gitee.controller;

import com.gitee.service.WareSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("stock")
public class StockController {

    @Value("${server.port}")
    String port;

    @Autowired
    private WareSkuService stockService;

    @RequestMapping("/reduct")
    public String reduct() {
        System.out.println("扣减库存");
        return "扣减库存:" + port;
    }


    @RequestMapping("/reduct2")
    public String reduct2() {
        int a = 1 / 0;
        System.out.println("扣减库存");
        return "扣减库存:" + port;
    }

    @RequestMapping("/reduct/{skuId}/{num}")
    public String reduct(@PathVariable("skuId") Long skuId, @PathVariable("num") Integer num) {
        stockService.reduct(skuId, num);
        return "扣减库存成功";
    }
}
